<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>搜索结果-牛马新闻中心</title>
    <link href="../CSS/Allnews.css" rel="stylesheet">
</head>
<body>
<div class="all-news">
    <table id="table1">
        <tr id="tr1">
            <td class="news-title" style="color:black;">标题</td><td>作者</td><td>类型</td><td>时间</td>
        </tr>
        <tr>
            <td class="news-title">标题</td><td>作者</td><td>类型类型</td><td>2099-90-90 09:09:09</td>
        </tr>
        <tr>
            <td class="news-title">标题</td><td>作者</td><td>类型类型</td><td>2099-90-90 09:09:09</td>
        </tr>
        <tr>
            <td class="news-title">标题</td><td>作者</td><td>类型类型</td><td>2099-90-90 09:09:09</td>
        </tr>
        <tr>
            <td class="news-title">标题</td><td>作者</td><td>类型类型</td><td>2099-90-90 09:09:09</td>
        </tr>
    </table>
</div>
<script type="text/javascript">
    function ajaxFunction() {
        var xmlHttp;
        try { // Firefox, Opera 8.0+, Safari
            xmlHttp = new XMLHttpRequest();
        } catch (e) {
            try {// Internet Explorer
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                }
            }
        }
        return xmlHttp;
    }
    // 创建AJAX
    function Onloading() {
        var request = ajaxFunction();
        // 2 发送请求 参数1:选择发送方式  参数2:发送地址(这里发送给一个Servlet)  参数3:是否异步传输(一般为true)
        request.open("POST", "./../SMS", true);			//全部新闻
        // 3 获取请求响应数据 注册监听  状态如果发生变化 会执行等号右边的函数
        request.onreadystatechange = function() {
            //前半段表示 已经能够正常处理。  再判断状态码是否是200
            if (request.readyState == 4 && request.status == 200) {
                //弹出响应的信息
                var test = eval("("+request.responseText+")");
                var news ="<tr id=\"tr1\">" +
                    "<td class=\"news-title\">标题</td><td>作者</td><td>类型</td><td>时间</td>" +
                    "</tr>";
                for(var i=0;i<test.length;i++){
                    news+='<tr><td class=\"news-title\">'+test[i].title+'</td><td>'+test[i].author+'</td><td>'+test[i].tname+'</td><td>'+test[i].time+'</td></tr>';
                    console.log('<tr><td class=\"news-title\">'+test[i].title+'</td><td>'+test[i].author+'</td><td>'+test[i].tname+'</td><td>'+test[i].time+'</td></tr>');
                }
                document.getElementById("table1").innerHTML=news;
                GYS();
            }
        }
        request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        request.send("search="+localStorage.getItem("check"));
    }
    Onloading();
</script>
<script type="text/javascript">
    function GYS(k){
        var NTitle = document.getElementsByClassName('news_title');
        for(var i=0;i<k;i++){
            NTitle[i].onmousedown=function () {
                this.style.color='red';
            }
            NTitle[i].onmouseup=function () {
                this.style.color='blue';
            }
        }
    }
</script>
<!--更改字体颜色-->
</body>
</html>